From f6395db397cef4b929ded8e0ab3274377bb7731a Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 15 Mar 2007 16:53:44 +0000 Subject: [PATCH] Jon McClinton and Robert Lipe add NMEA realtime tracking output, tweak realtime tracking output for KML, and enhance reliability for Garmin/USB tracking on Linux and Mac. --- defs.h | 4 ++-- globals.c | 1 + kml.c | 17 ++++++++++++++--- main.c | 40 ++++++++++++++++++++++++++++------------ nmea.c | 31 ++++++++++++++++++++++++++++--- 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/defs.h b/defs.h index 3ed825b43..28609b2b4 100644 --- a/defs.h +++ b/defs.h @@ -425,10 +425,10 @@ typedef struct { } bounds; typedef struct { - int request_terminate; + volatile int request_terminate; } posn_status; - +extern posn_status tracking_status; typedef void (*ff_init) (char const *); typedef void (*ff_deinit) (void); diff --git a/globals.c b/globals.c index f51201caa..3891a45e7 100644 --- a/globals.c +++ b/globals.c @@ -28,3 +28,4 @@ const char gpsbabel_version[] = VERSION; time_t gpsbabel_now; /* gpsbabel startup-time; initialized in main.c with time() */ time_t gpsbabel_time; /* gpsbabel startup-time; initialized in main.c with current_time(), ! ZERO within testo ! */ +posn_status tracking_status; diff --git a/kml.c b/kml.c index c544a041f..6ecc92bfd 100644 --- a/kml.c +++ b/kml.c @@ -280,7 +280,6 @@ kml_wr_position_init(const char *fname) * matters in this mode, turn the pretty formatting off. */ do_indentation = 0; - kml_wr_init(posnfilenametmp); max_position_points = atoi(opt_max_position_points); } @@ -296,10 +295,18 @@ kml_wr_deinit(void) MOVEFILE_REPLACE_EXISTING); #endif rename(posnfilenametmp, posnfilename); + } + ofd = NULL; +} + +static void +kml_wr_position_deinit(void) +{ + kml_wr_deinit(); + if (posnfilenametmp) { xfree(posnfilenametmp); posnfilenametmp = NULL; } - ofd = NULL; } /* @@ -894,6 +901,8 @@ kml_wr_position(waypoint *wpt) { static time_t last_valid_fix; + kml_wr_init(posnfilenametmp); + if (!posn_trk_head) { posn_trk_head = route_head_alloc(); track_add_head(posn_trk_head); @@ -940,6 +949,8 @@ kml_wr_position(waypoint *wpt) waypoint *tonuke = (waypoint *) QUEUE_FIRST(&posn_trk_head->waypoint_list); track_del_wpt(posn_trk_head, tonuke); } + +// kml_wr_deinit(); } ff_vecs_t kml_vecs = { @@ -954,5 +965,5 @@ ff_vecs_t kml_vecs = { NULL, kml_args, CET_CHARSET_UTF8, 1, /* CET-REVIEW */ - { NULL, NULL, NULL, kml_wr_position_init, kml_wr_position, kml_wr_deinit } + { NULL, NULL, NULL, kml_wr_position_init, kml_wr_position, kml_wr_position_deinit } }; diff --git a/main.c b/main.c index 6c1aabfb3..dd8161d47 100644 --- a/main.c +++ b/main.c @@ -25,9 +25,12 @@ #include "csv_util.h" #include "inifile.h" #include +#include #define MYNAME "main" +void signal_handler(int sig); + typedef struct arg_stack_s { int argn; int argc; @@ -142,6 +145,7 @@ usage(const char *pname, int shorter ) " -s Synthesize shortnames\n" " -r Process route information\n" " -t Process track information\n" +" -T Process realtime tracking information\n" " -w Process waypoint information [default]\n" " -b Process command file (batch mode)\n" " -c Character set for next operation\n" @@ -345,7 +349,7 @@ main(int argc, char *argv[]) ivecs->rd_init(fname); ivecs->read(); ivecs->rd_deinit(); - + cet_convert_strings(global_opts.charset, NULL, NULL); cet_convert_deinit(); @@ -618,21 +622,27 @@ main(int argc, char *argv[]) } if (ovecs) { - if (!ovecs->position_ops.wr_init || - !ovecs->position_ops.wr_position || - !ovecs->position_ops.wr_deinit) { - fatal ("This output format does not support realtime positioning.\n"); + if ( !ovecs->position_ops.wr_position ) { + fatal ("This output format does not support output of realtime positioning.\n"); } } - while (1) { - posn_status status; + if (signal(SIGINT, signal_handler) == SIG_ERR) { + fatal ("Couldn't install the exit signal handler.\n"); + } + + if (ovecs->position_ops.wr_init) { + ovecs->position_ops.wr_init(ofname); + } + + tracking_status.request_terminate = 0; + while (!tracking_status.request_terminate) { waypoint *wpt; - status.request_terminate = 0; - wpt = ivecs->position_ops.rd_position(&status); + tracking_status.request_terminate = 0; + wpt = ivecs->position_ops.rd_position(&tracking_status); - if (status.request_terminate) { + if (tracking_status.request_terminate) { if (wpt) { waypt_free(wpt); } @@ -640,9 +650,9 @@ main(int argc, char *argv[]) } if (wpt) { if (ovecs) { - ovecs->position_ops.wr_init(ofname); +// ovecs->position_ops.wr_init(ofname); ovecs->position_ops.wr_position(wpt); - ovecs->position_ops.wr_deinit(); +// ovecs->position_ops.wr_deinit(); } else { /* Just print to screen */ waypt_disp(wpt); @@ -674,3 +684,9 @@ main(int argc, char *argv[]) #endif exit(0); } + +void signal_handler(int sig) +{ + tracking_status.request_terminate = 1; +} + diff --git a/nmea.c b/nmea.c index fcc78e486..ac6181c79 100644 --- a/nmea.c +++ b/nmea.c @@ -174,8 +174,10 @@ static char *optdate = NULL; static char *getposnarg = NULL; static char *opt_sleep = NULL; static char *opt_baud = NULL; +static char *opt_append = NULL; static long sleepus = 0; static int getposn; +static int append_output; static time_t last_time = -1; static double last_read_time; /* Last timestamp of GGA or PRMC */ @@ -193,6 +195,7 @@ arglist_t nmea_args[] = { { "get_posn", &getposnarg, "Return current position as a waypoint", NULL, ARGTYPE_BOOL, ARG_NOMINMAX}, {"pause", &opt_sleep, "Decimal seconds to pause between groups of strings", NULL, ARGTYPE_INT, ARG_NOMINMAX }, + {"append_positioning", &opt_append, "Append realtime positioning data to the output file instead of truncating", "0", ARGTYPE_BOOL, ARG_NOMINMAX }, {"baud", &opt_baud, "Speed in bits per second of serial port (baud=4800)", NULL, ARGTYPE_INT, ARG_NOMINMAX }, ARG_TERMINATOR }; @@ -266,7 +269,9 @@ nmea_rd_deinit(void) static void nmea_wr_init(const char *portname) { - file_out = gbfopen(portname, "w+", MYNAME); + append_output = atoi(opt_append); + + file_out = gbfopen(portname, append_output ? "a+" : "w+", MYNAME); if ( opt_sleep ) { if ( *opt_sleep ) { @@ -276,7 +281,7 @@ nmea_wr_init(const char *portname) sleepus = -1; } } - + mkshort_handle = mkshort_new_handle(); setshort_length(mkshort_handle, atoi(snlenopt)); } @@ -1201,6 +1206,25 @@ nmea_write(void) track_disp_all(nmea_track_init, NULL, nmea_trackpt_pr); } +static void +nmea_wr_posn_init(const char *fname) +{ + nmea_wr_init(fname); +} + +static void +nmea_wr_posn(waypoint *wpt) +{ + nmea_trackpt_pr(wpt); +} + +static void +nmea_wr_posn_deinit(void) +{ +// nmea_wr_deinit(); +} + + ff_vecs_t nmea_vecs = { ff_type_file, { ff_cap_read | ff_cap_write, ff_cap_read | ff_cap_write, ff_cap_none}, @@ -1213,7 +1237,8 @@ ff_vecs_t nmea_vecs = { NULL, nmea_args, CET_CHARSET_ASCII, 0, /* CET-REVIEW */ - { nmea_rd_posn_init, nmea_rd_posn, nmea_rd_deinit, NULL, NULL, NULL } + { nmea_rd_posn_init, nmea_rd_posn, nmea_rd_deinit, + nmea_wr_posn_init, nmea_wr_posn, nmea_wr_posn_deinit } }; /* -- 2.30.2